package com.tansun.easycare.rule.approval.web;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import com.tansun.easycare.rule.approval.entity.RuleEditorInfo;
import com.tansun.easycare.rule.common.RuleBaseController;

@Controller
@RequestMapping(value = "/ruleProj/")
public class RuleApprovalController extends RuleBaseController {

    /**
     * 转到工作流待办列表
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    @RequestMapping("ruleApprovalTodoList/index")
    public String todoListIndex(HttpServletRequest request, HttpServletResponse response) throws Exception {
        String projectCode = request.getParameter("projectCode");
        String modelName = request.getParameter("modelName");
        return "redirect:" + "/wf/task/taskList?status=1&taskExpandCondition['projectCode']="+projectCode+"&projectCode=" + projectCode + "&modelName=" + modelName;
    }

    /**
     * 转到工作流已办
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    @RequestMapping("ruleApprovalCompleteList/index")
    public String completeListIndex(HttpServletRequest request, HttpServletResponse response) throws Exception {
        String projectCode = request.getParameter("projectCode");
        String modelName = request.getParameter("modelName");
        return "redirect:" +"/wf/task/taskList?status=3&taskExpandCondition['projectCode']="+projectCode+"&projectCode=" + projectCode + "&modelName=" + modelName;
    }


    /**
     * 发起审批
     */
    @RequestMapping("ruleApproval/startProcess")
    public String startProcess(HttpServletRequest request, HttpServletResponse response) throws Exception {
        String projectCode = request.getParameter("projectCode");
        String modelName = request.getParameter("modelName");
        return "redirect:" +"/wf/task/taskList?status=3&projectCode=" + projectCode + "&modelName=" + modelName;
    }

//    @Autowired
//    private WfUserService wfUserService;


    /**
     * 获取选人界面弹出框的用户列表
     * @param model
     * @return
     */
    @RequestMapping(value = "getWfOperationUserData")
    public String getWfUserData(String taskId, Model model, @RequestBody RuleEditorInfo info) {
        //分页时回调方法
//        Page<User> pagebefore=  new Page<User>();
//        pagebefore.setPageNo(info.getCurrentPage());
//        pagebefore.setPageSize(info.getPageSize());
//        pagebefore.setFuncName("setWfOperationUserTableData");
//
//        Page<User> page= new Page<User>();
//        try {
//            page = wfUserService.getWfOperationUser(pagebefore, info, taskId);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        model.addAttribute("page", page);
//
//        model.addAttribute("checkType", "radio");
//        model.addAttribute("candidateRoles", info.getRoleCodes() == null ? new ArrayList<>(): JSON.toJSONString(info.getRoleCodes() ));
//        model.addAttribute("tempData", info.getTempData() == null ? "{}": info.getTempData() );
        return "wf/wfOperationUserTable";
    }

}
